package GameBoard;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JButton;

/**
 * Board Component Class
 * @author Daniel and Hardy
 *
 */

public class BoardComponent extends JButton{
	private int col;// X position on grid layout
	private int row;// Y position on grid layout
	private int state;
	public Color mouseOver;
	
	/**
	 * Constructor
	 * @param a new x position
	 * @param b new y position
	 */
	public BoardComponent (int a, int b) {
		col = b;
		row = a;
		setBackground(Color.GRAY);
		setMaximumSize(new Dimension(100,100));
		setMinimumSize(new Dimension(30,30));
		setPreferredSize(new Dimension(50,50));
		setState(4);
	}
	
	/**
	 * SetX method
	 * @param a new x position
	 */
	public void setRow (int a) {
		col = a;
	}
	
	/**
	 * SetY method	
	 * @param b new y position
	 */
	public void setCol (int b) {
		row = b;
	}
	
	/**
	 * getX method
	 */
	public int getCol () {
		return col;
	}
	
	/**
	 * getY method
	 */
	public int getRow () {
		return row;
	}
	
	public int getXCo () {
		return (int) this.getLocationOnScreen().getX()+1;
	}
	
	public int getYCo () {
		return (int) this.getLocationOnScreen().getY()+1;
	}
	
	/**
	 * changeState method
	 * changes state of the square - which player has control of it, and whether it is dead
	 */
	public void setState(int s) {
		state = s;
		if (state == -1)
			setBackground(Color.black);
	}
	
	public int getState() {
		return state;
	}
	
	public void alternate() {
		mouseOver = getBackground();
		switch(state) {
		case 0:
		case 1:
		case 4:
			setBackground(getBackground().darker());
			break;
		case -1:
		case 2:
		case 3:
			setBackground(getBackground().brighter());
			break;
		}
	}
	
	public void original() {
		setBackground(mouseOver);
	}
	
	public void reset() {
		switch(state) {
		case -1:
			this.setBackground(Color.black);
			mouseOver = getBackground();
			break;
		case 0:
			this.setBackground(Color.green);
			mouseOver = getBackground();
			break;
		case 2:
			this.setBackground(Color.green.darker().darker());
			mouseOver = getBackground();
			break;
		case 1:
			this.setBackground(Color.blue);
			mouseOver = getBackground();
			break;
		case 3:
			this.setBackground(Color.blue.darker().darker());
			mouseOver = getBackground();
			break;
		case 4:
			setBackground(Color.GRAY.brighter());
			mouseOver = getBackground();
			break;
		}
	}
}
